package com.example.aircraftticketingsystemserver.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.aircraftticketingsystemserver.entity.Flight;
import com.example.aircraftticketingsystemserver.entity.Notification;
import com.example.aircraftticketingsystemserver.mapper.FlightsMapper;
import com.example.aircraftticketingsystemserver.mapper.NotificationMapper;
import com.example.aircraftticketingsystemserver.service.IFlightsService;
import com.example.aircraftticketingsystemserver.service.INotificationService;
import com.example.aircraftticketingsystemserver.utils.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class NotificationServiceImpl extends ServiceImpl<NotificationMapper, Notification> implements INotificationService {
    @Resource
    NotificationMapper notificationMapper;
    @Override
    public void addNotice(Notification notification) {
        notificationMapper.addNotice(notification);
    }

    @Override
    public void deleteNotice(List<Integer> noticeIds) {
        notificationMapper.deleteNotice(noticeIds);
    }

    @Override
    public Page getNoticeByUserId(Integer pageNo, Integer pageSize, Integer userId) {
       Page page=new Page();
       PageHelper.startPage(pageNo,pageSize);
       List<Notification>notifications=notificationMapper.selectNoticeByUserId(userId);
        PageInfo<Notification> info = new PageInfo<>(notifications);
        page.setPage(info.getList());
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setHasNext(info.isHasNextPage());
        page.setHasPre(info.isHasPreviousPage());
        page.setTotal(info.getTotal());
        page.setPageCount(info.getPages());
        return page;
    }

}
